<?php

App::uses('CakeEmail', 'Network/Email');

/**
 * Class Task
 */
class Task extends AppModel {

	protected $_email = null;

	/**
	 * @return null
	 */
	public function getEmail() {
		return $this->_email;
	}

	/**
	 * @param \CakeEmail $email
	 */
	public function setEmail(CakeEmail $email) {
		$this->_email = $email;
	}

	public function afterSave($created, $options = []) {
		parent::afterSave($created, $options);
		if ($created) {
			$adminEmail = Configure::read('App.adminEmail');
			$replyEmail = Configure::read('App.replyEmail');
			$Email = $this->getEmail();
			$Email->from($replyEmail)
			      ->to($adminEmail)
			      ->subject(__('New task created'))
			      ->send(__('A new task was created'));
		}
	}
}
